<template lang="html">
  <d2-container>
    <page-header
      slot="header"
      ref="pageHeader"
      @doSearch="doSearch"
      @doReset="doReset"
    />

    <!-- 中间内容容器 -->
    <div v-loading="loading" class="loading-wrapper">
      <el-table
        ref="multipleTable"
        border
        stripe
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column type="index" width="50" label="序号" align="center" />
        <el-table-column prop="taskName" label="任务名称" align="center" />
        <el-table-column prop="inTimeNo" label="处理批次" align="center" width="150px"/> 
        <el-table-column prop="inParam" label="参数" align="center" show-overflow-tooltip/> 
        <el-table-column prop="begTime" label="开始时间" align="center" width="160px"/> 
        <el-table-column prop="endTime" label="结束时间" align="center" width="160px"/> 
        <el-table-column prop="inNum" label="归集数" align="center" width="70px"/> 
        <el-table-column prop="result_text" label="结果" align="center" width="70px">
          <template slot-scope="{ row }">
            <el-tooltip v-if="row.inNum > 0" class="item" effect="dark" content="详情" placement="right-start">
               <el-button type="text" :class="row.result===2?'danger':(row.result===1?'success':'primary')" @click="doView(row)">{{row.result_text}}</el-button> 
            </el-tooltip>
            <el-button v-if="row.inNum === 0" type="text" :class="row.result===2?'danger':(row.result===1?'success':'primary')">{{row.result_text}}</el-button> 
           </template>
         </el-table-column>  
        <el-table-column prop="resultRemarks" label="结果描述" align="center" show-overflow-tooltip/> 
        <el-table-column label="操作" align="center" width="80" fixed="right">
          <template slot-scope="{ row }">
            <el-button type="text" @click="doAgain(row)">重新处理</el-button> 
          </template>
        </el-table-column>
      </el-table>
    </div>

    <view-dialog :dialogVisible.sync="viewDialogVisible" :logId="id" />
    <!-- 底部分页 -->
    <footer-page
      slot="footer"
      :pageSize="pageSize"
      :currentPage="currentPage"
      :total="total"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
  </d2-container>
</template>

<script>
import PageHeader from "./components/page-header";
import ViewDialog from "./components/view-dialog";
import { PageList,RedoTask} from "api/dtmg/tasklog";
import tableMixinKeepAlive from "mixins/tableMixinKeepAlive";
export default {
  name: "dtmg-tasklog",
  components: {
    PageHeader,
    ViewDialog
  },
  mixins: [tableMixinKeepAlive],
  data() {
    return {
      multipleSelection: [], 
      viewDialogVisible: false,
      // 接口api
      getTableListSyncMethod: PageList,
      // 当前行数据id
      id: "",
      resultOps: [{"value":0,"name":"处理中"},{"value":1,"name":"成功"},{"value":2,"name":"失败"}],
    };
  },
  async created() { 
  },
  methods: {

    /**
     * 列表数据格式化
     */
    tableDataFormat(data) { 
      data.map((item) => {
        const { result } = item;
        item.result_text = this.resultOps.find((r) => r.value === result)?.name;
      });
      return data;
    },
    doView(row) {
      this.id = row.id;
      this.viewDialogVisible = true;
    },
    async doAgain(row){ 
      try {
        await this.$myConfirm("重新处理任务");
        const { id } = row; 
        await RedoTask(id); 
        this.$message.success(`处理成功`);
        this.$emit("success"); 
        this.getTableData();
      } catch (e) {
       // console.log(e);
      } finally {
        this.btnLoading = false;
      }
    },  
  },
};
</script>
